global dir = "C:\Users\mrueda\Documents\Emory\Papers\Networks_persistance\do_files\do_files_APSA21\post_JOP\Replication_BJPS\"	

cd "$dir"

use  "Data\cand_level_persist_rep.dta",clear


	global balance_ind women age black indi_bkg leftist rightwing sanc_before ilegal pol_exp_d elec_exp_d all 
	global balance_fin all total_income donations_total 
	global balance_donors family cont_donor_102 cont_donor_101 contraloria above_lim    
	global balance_all $balance_ind $balance_fin $balance_donors


	
	
	texdoc close 
	cap erase "$dir/Tables/TableC1.tex"
	texdoc init "$dir/Tables/TableC1.tex", force

	tex \begin{table}[tbph]
	tex \caption{Candidate characteristics around the electoral victory cutoff}\label{tab:smooth_win}
	tex \begin{center}
	tex \scalebox{.8}{%
	tex {\normalsize
	tex \begin{tabular}{l c c c c c c c c}
	tex \toprule[1.5pt]
	tex \multicolumn{1}{c}{} & Mean &  Std. Dev. & Victory & CI 95\% &
	tex Obs. & Band. Obs.  & Bandwith & p-value \\
	tex & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\
	tex \hline
	tex \addlinespace
	tex \multicolumn{6}{l}{\textit{Panel A:Candidates' characteristics}}\\
	tex \addlinespace
	
	foreach x in $balance_all{	
	
		*Summary statistics for the mean
		sum `x' if margin_victory!=.
			local mean_`x' : di %5.3f r(mean)
			local sd_`x' : di %5.3f r(sd) 
		
		*Regressions
		rdrobust `x' margin_victory if (rank==1 | rank==2), all vce(cluster muni_code) 
		
		*Local's for the table
		local bw_`x' : di %9.2f `e(h_l)'
		local ser_`x' = round(`e(se_tau_rb)',0.001)
		local Neff_`x' = `e(N_h_l)'+`e(N_h_r)'
		local N_`x' = `e(N)'
		local poly_`x' = `e(p)'
		local beta1_`x' : di %5.3f `e(tau_cl)'
		local beta2_`x' : di %5.3f `e(tau_cl)'

		*Confidence intervals
			local ser1_`x' : di %5.3f `e(ci_l_rb)'
			local ser2_`x' : di %5.3f `e(ci_r_rb)'
			
/* HERE*/	local em1_`x' = (`beta1_`x''/`mean_`x'')*100 
			local em1_`x' : di %5.2f `em1_`x''
			
		*P-values
		local pval1_`x' : di %5.3f `e(pv_cl)'
		local pval2_`x' : di %5.3f `e(pv_rb)'
		
		
	}	

	
	

	
	
	*Table continue
	tex \ Women & `mean_women' & `sd_women' & `beta2_women' & [`ser1_women',`ser2_women'] & `N_women' & `Neff_women' & `bw_women' & `pval2_women' \\
	tex \ Age & `mean_age' & `sd_age' & `beta2_age' & [`ser1_age',`ser2_age'] & `N_age' & `Neff_age' & `bw_age' & `pval2_age' \\
	tex \ Black & `mean_black' & `sd_black' & `beta2_black' & [`ser1_black',`ser2_black'] & `N_black' & `Neff_black' & `bw_black' & `pval2_black' \\
	tex \ Indigenous & `mean_indi_bkg' & `sd_indi_bkg' & `beta2_indi_bkg' & [`ser1_indi_bkg',`ser2_indi_bkg'] & `N_indi_bkg' & `Neff_indi_bkg' & `bw_indi_bkg' & `pval2_indi_bkg' \\
	tex \ Left wing & `mean_leftist' & `sd_leftist' & `beta2_leftist' & [`ser1_leftist',`ser2_leftist'] & `N_leftist' & `Neff_leftist' & `bw_leftist' & `pval2_leftist' \\
	tex \ Right wing & `mean_rightwing' & `sd_rightwing' & `beta2_rightwing' & [`ser1_rightwing',`ser2_rightwing'] & `N_rightwing' & `Neff_rightwing' & `bw_rightwing' & `pval2_rightwing' \\
	tex \ Sanctioned & `mean_sanc_before' & `sd_sanc_before' & `beta2_sanc_before' & [`ser1_sanc_before',`ser2_sanc_before'] & `N_sanc_before' & `Neff_sanc_before' & `bw_sanc_before' & `pval2_sanc_before' \\
	tex \ Illegal Registration of ID. & `mean_ilegal' & `sd_ilegal' & `beta2_ilegal' & [`ser1_ilegal',`ser2_ilegal'] & `N_ilegal' & `Neff_ilegal' & `bw_ilegal' & `pval2_ilegal' \\
	tex \ Political experience & `mean_pol_exp_d' & `sd_pol_exp_d' & `beta2_pol_exp_d' & [`ser1_pol_exp_d',`ser2_pol_exp_d'] & `N_pol_exp_d' & `Neff_pol_exp_d' & `bw_pol_exp_d' & `pval2_pol_exp_d' \\
	tex \ Held office before & `mean_elec_exp_d' & `sd_elec_exp_d' & `beta2_elec_exp_d' & [`ser1_elec_exp_d',`ser2_elec_exp_d'] & `N_elec_exp_d' & `Neff_elec_exp_d' & `bw_elec_exp_d' & `pval2_elec_exp_d' \\
	tex \\
	
	tex \multicolumn{6}{l}{\textit{Panel B: General funding covariates}}\\
	tex \addlinespace	
	tex \ Donors (all) & `mean_all' & `sd_all' & `beta2_all' & [`ser1_all',`ser2_all'] & `N_all' & `Neff_all' & `bw_all' & `pval2_all' \\
	tex \ Campaign revenue & `mean_total_income' & `sd_total_income' & `beta2_total_income' & [`ser1_total_income',`ser2_total_income'] & `N_total_income' & `Neff_total_income' & `bw_total_income' & `pval2_total_income' \\
	tex \ Donations /Revenue & `mean_donations_total' & `sd_donations_total' & `beta2_donations_total' & [`ser1_donations_total',`ser2_donations_total'] & `N_donations_total' & `Neff_donations_total' & `bw_donations_total' & `pval2_donations_total' \\

	tex \\
	tex \multicolumn{6}{l}{\textit{Panel C: Donors characteristics}}\\
	tex \addlinespace	
	tex \ Family & `mean_family' & `sd_family' & `beta2_family' & [`ser1_family',`ser2_family'] & `N_family' & `Neff_family' & `bw_family' & `pval2_family' \\
	tex \ Avg. Donation (non-family) & `mean_cont_donor_102' & `sd_cont_donor_102' & `beta2_cont_donor_102' & [`ser1_cont_donor_102',`ser2_cont_donor_102'] & `N_cont_donor_102' & `Neff_cont_donor_102' & `bw_cont_donor_102' & `pval2_cont_donor_102' \\
	tex \ Avg. Donation (family) & `mean_cont_donor_101' & `sd_cont_donor_101' & `beta2_cont_donor_101' & [`ser1_cont_donor_101',`ser2_cont_donor_101'] & `N_cont_donor_101' & `Neff_cont_donor_101' & `bw_cont_donor_101' & `pval2_cont_donor_101' \\
	tex \ Comptroller sanction & `mean_contraloria' & `sd_contraloria' & `beta2_contraloria' & [`ser1_contraloria',`ser2_contraloria'] & `N_contraloria' & `Neff_contraloria' & `bw_contraloria' & `pval2_contraloria' \\
	tex \ Above limit & `mean_above_lim' & `sd_above_lim' & `beta2_above_lim' & [`ser1_above_lim',`ser2_above_lim'] & `N_above_lim' & `Neff_above_lim' & `bw_above_lim' & `pval2_above_lim' \\

	
	tex \addlinespace
	tex \midrule[1 pt]
	tex \end{tabular}
	tex }}
	tex \parbox{160mm}{ \scriptsize{
	tex Columns 1 and 2 report the descriptive statistics. Column 3 reports local linear estimates of average treatment effects at the cutoff estimated with triangular kernel weights and optimal MSE bandwidth (reported in column 7). Columns 4 and 8 report 95\% robust confidence intervals and robust p-values computed following \citep{calonico_robust_2014}. Columns 5 and 6 report total observations and observations in optimal MSE bandwidth. Sanctioned indicates the candidate has been sanctioned by the Office of the Inspector General. Donors and Donations include the totals for non-family and family donors. Family is the fraction of donors who are family members of the candidate. Above limit is the fraction of donors contributing above the individual legal limit. 
	tex }
	tex }
	tex \end{center}
	tex \end{table}
	cap texdoc close
